package com.sykj.why.controller.front.project;

import com.sykj.why.exception.WhyException;
import com.sykj.why.handler.Response;
import com.sykj.why.mongo.document.entity.ProjectT;
import com.sykj.why.mongo.enums.exception.ResultEnum;
import com.sykj.why.mongo.service.ProjectTService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Eleven
 * @date 2019/7/8
 * @desc 前端非遗项目控制访问层
 */

@RestController
@RequestMapping("/front/project")
@Slf4j
@Api(value = "/front/project",description = "前端非遗项目控制访问层")
public class FrontProjectController {

    @Autowired
    private ProjectTService projectTService;

    /**
     * 申报非遗项目
     * @param projectT
     * @return
     */
    @RequestMapping(value = "/apply",method = RequestMethod.POST)
    @ApiOperation(value = "/apply",notes = "申报非遗项目")
    public ResponseEntity apply(@RequestBody ProjectT projectT){
        try {
            projectTService.saveProject(projectT);
            return Response.success("申报成功");
        } catch (WhyException e) {
            return Response.serverError(e.getMessage(), e.getCode());
        } catch (Exception e) {
            log.error("申报非遗项目出现异常，{}", e.getMessage());
            return Response.serverError(ResultEnum.UNERROR.getMessage(), ResultEnum.UNERROR.getCode());
        }
    }

}
